package tw.twandroidproj.app.ui.Apply;

import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tw.twandroidproj.app.R;

public class job_apply extends AppCompatActivity implements AdapterView.OnItemClickListener{

    private ListView listview;
    private List<Map<String,Object>> dataList;
    private SimpleAdapter sim_adapter;
    EditText apply_description;
    Map<String,Object> map= new HashMap<String,Object>();
//    NetworkManager apply_networkManager;
//    final int job_id=1;
//    HashMap<String, String> postmap;
//    private List<Resume> mResume;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.apply_job);
        listview = (ListView) findViewById(R.id.resume_listView);
        dataList = new ArrayList<Map<String,Object>>();
//        apply_networkManager = NetworkManager.getInstance(this);
        sim_adapter = new SimpleAdapter(this, getData(), R.layout.apply_resumeitem, new String[]{"resume_name"}, new int[]{R.id.resumeToJob_name});
        listview.setAdapter(sim_adapter);
        listview.setOnItemClickListener(this);


    }

    private List<Map<String,Object>> getData() {
        for (int i=1;i<=3;i++){
            map.put("resume_name","简历");
        dataList.add(map);
    }

//         apply_networkManager.getResumeList(new OnResponseListener<List<Resume>>() {
//                @Override
//                public void onSuccess(List<Resume> result) {
//                    mResume=result;
//                    for (int i=0;i<result.size();i++) {
//                       map.put("resume_name",result.get(i).getName());
//                       map.put("create_time", result.get(i).getCreated_at());
//                       dataList.add(map);
//                    }
//                }
//               @Override
//                 public void onFailed(ErrorModel errorModel) {}
//         });
        return dataList;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

        LayoutInflater inflater = LayoutInflater.from(this);
        View dia_view = inflater.inflate(R.layout.resume_dialog,null);
        AlertDialog.Builder builder= new AlertDialog.Builder(this);
        builder.setTitle("提交简历");
        builder.setView(dia_view);
        AlertDialog dialog=builder.create();
        dialog.show();

        Button apply_submit = (Button) dia_view.findViewById(R.id.applySubmit);
        apply_description = (EditText) dia_view.findViewById(R.id.applyDescription);

//        postmap = new HashMap<String, String>();
//        postmap.put("job_id",String.valueOf(job_id));
//        postmap.put("resume_id","1");
//        postmap.put("description", String.valueOf(apply_description.getText()));

        apply_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                apply_networkManager.postJobApply(postmap, new OnResponseListener<JobApply>() {
//                    @Override
//                    public void onSuccess(JobApply result) {
//                        Log.i("apply","提交成功");
//                    }
//
//                    @Override
//                    public void onFailed(ErrorModel errorModel) {
//                        Log.i("apply","提交失败");
//                    }
//                });

            }
        });


    }

}


